import request from '@/utils/request.js'
// import { useStore } from "vuex";
// const store=useStore()
import store from '@/store'

// 频道接口
export const allChannelListAPI = () => request({ url: '/v1_0/channels', method: 'get' })

// 用户登录
export const loginAPI = ({ mobile, code }) => request({ url: '/v1_0/authorizations', method: 'post', data: { mobile, code } })

// 首页频道数据
export const userChannelAPI = () => request({
  url: '/v1_0/user/channels',

  // !先把请求头+token给禁掉，因为在request中在拦截器上添加过
  // headers: {
  //   Authorization: 'Bearer ' + store.state.login.token
  // }
})

// 文章数据列表
export const articlesListAPI = ({ channelId, timestamp }) => request({
  url: '/v1_0/articles',
  params: {
    channel_id: channelId,
    timestamp: timestamp || (new Date()).getTime()
  }
})

// 文章 - 不感兴趣
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: target
    },
    // headers: {
    //   Authorization: 'Bearer ' + store.state.login.token
    // }
  })
}

// 文章 - 举报
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: target,
      type: type,
      remark: remark
    },
    // headers: {
    //     Authorization: 'Bearer ' + store.state.login.token
    // }
  })
}


// 频道 - 更新已选
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}

// 用户 - 基本资料
export const userInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}